package com.red.star.wechat.data.mappers;


import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.Merchant;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: Yenan
 * @Description:
 * @Date: Created in 14:30 2018/2/5
 */
public interface MerchantMapper extends MyMapper<Merchant> {
    List getAllCategoryByMallCode(String mallCode);

    List<Merchant> getMerchantsByCategoryAndMallCode(@Param("category") String category, @Param("mallCode") String mallCode);

    List<Merchant> getMerchantsByMallCode(String mallCode);

    Merchant getMerchantByMallCode(String mallCode);

    Merchant getMerchantById(String id);

    List<Merchant> findAllMerchantName(@Param("mallCode") String mallCode);

    List<Merchant> findAllmerchantNameArea(@Param("mallCode") String mallCode);

    List<String> findNameList(@Param("cardName") String cardName);

    @Select(value = "select DISTINCT t.brand_name from t_merchant t where t.brand_name is not null")
    public List<String> findAllBrandName();

    public List<Merchant> findMerchantByMallCode(@Param("mallCode") String mallCode);

    public List<Merchant> findAllmerchantNameAndId(@Param("mallCode") String mallCode);

    public List<String> findBrandNameByMallCode(@Param("mallCode") String mallCode);

    @Select("SELECT tm.market_name, tm.brand_name, tm.main_category_name, tm.floor_name, tm.market_address, tm.shop_name FROM t_merchant AS tm JOIN t_employee AS te ON tm.id = te.merchant_id WHERE te.id = #{employeeId}")
    Merchant findMerchantByEmployeeId(@Param("employeeId") Integer employeeId);

    //根据龙翼系统商户Id查询shopId
    Merchant findMerchantByShopId(Integer shopId);

    void updateMerchantStatus(@Param("marketId") String marketId,@Param("shopList") List<Integer> shopList);

    @Select("select * from t_merchant where brand_name=#{brandName} and market_name=#{marketName}")
    List<Merchant> listMerchantByName(@Param("brandName") String brandName, @Param("marketName") String marketName);

    List<Merchant> listMerchantByBrandName(@Param("brandNameList") List<String> brandNameList, @Param("marketNameList") List<String> marketNameList);

    Merchant findByBrandName(@Param("brandName") String brandName, @Param("marketName") String marketName);

    /**
     * 根据shopName查询商户
     * 存在多个只取一条
     *
     * @param shopName
     * @return
     */
    @Select(value = "select t.id from t_merchant t where t.shop_name = #{shopName} limit 1")
    Merchant findOnlyByShopName(@Param("shopName") String shopName);

    /**
     * 根据shopName查询商户
     * 存在多个只取一条
     *
     * @param shopName
     * @return
     */
    @Select(value = "select t.id from t_merchant t where t.shop_name = #{shopName} and t.market_id = #{mallCode} limit 1;")
    Merchant findOnlyByMallAShop(@Param("mallCode") String mallCode, @Param("shopName") String shopName);

    /**
     * 根据推送电话确定唯一品牌
     *
     * @param pushMobile
     * @return
     */
    Merchant findOnlyByPushMobile(@Param("pushMobile") String pushMobile);

    /**
     * 根据brandName查询商户
     * 存在多个只取一条
     * @param brandName
     * @param marketName
     * @return
     */
    Merchant findOnlyByBrandName(@Param("brandName") String brandName, @Param("marketName") String marketName);

    @Select("SELECT tm.* FROM t_merchant AS tm JOIN t_employee AS te ON tm.id = te.merchant_id WHERE te.id = #{employeeId} and te.status=0 and te.type=0")
    Merchant findMerchantByBindEmployeeId(@Param("employeeId") Integer employeeId);

    List<Merchant> findMerchantsByBrandName(Merchant merchant);

    List<Merchant> findStartMerchantByShopId(Integer shopId);
}
